import { Injectable } from '@angular/core';
import {BadgeComponent, BadgePipe, SimpleJsonFormatter, SimplePipe, UnitPipe} from '../../../ng-tools';


@Injectable({
  providedIn: 'root'
})
export class DvbConfigFormatterService {
  name: SimpleJsonFormatter = {propName: 'name', displayName: '配置名称'};
  delivery_system: SimpleJsonFormatter = {propName: 'delivery_system', displayName: '调制器模式'};
  freq: SimpleJsonFormatter = {propName: 'freq', displayName: '频率'};
  time: SimpleJsonFormatter = {propName: 'time', displayName: '运行时间'};
  srate: SimpleJsonFormatter = {propName: 'srate', displayName: '符号率'};
  coderate: SimpleJsonFormatter = {propName: 'coderate', displayName: '码率'};
  tuner: SimpleJsonFormatter = {propName: 'tuner', displayName: '调谐器'};
  modulation: SimpleJsonFormatter = {propName: 'modulation', displayName: 'QAM类型'};
  multicast_iface4: SimpleJsonFormatter = {propName: 'multicast_iface4', displayName: '组播输出网卡'};
  multicast_ipv4: SimpleJsonFormatter = {propName: 'multicast_ipv4', displayName: '是否开启组播'};
  common_port: SimpleJsonFormatter = {propName: 'common_port', displayName: '组播端口'};
  multicast_ttl: SimpleJsonFormatter = {propName: 'multicast_ttl', displayName: '组播ttl值'};
  autoconfiguration: SimpleJsonFormatter = {propName: 'autoconfiguration', displayName: '自动模式'};
  multicast_auto_join: SimpleJsonFormatter = {propName: 'multicast_auto_join', displayName: '自动加入多播组'};
  ip_http: SimpleJsonFormatter = {propName: 'ip_http', displayName: '单播绑定ip'};
  dvr_buffer_size: SimpleJsonFormatter = {propName: 'dvr_buffer_size', displayName: 'DVR缓冲区大小'};
  dvr_thread: SimpleJsonFormatter = {propName: 'dvr_thread', displayName: '检索数据包'};
  dvr_thread_buffer_size: SimpleJsonFormatter = {propName: 'dvr_thread_buffer_size', displayName: 'DVR_thread缓冲区大小'};
  scam_support: SimpleJsonFormatter = {propName: 'scam_support', displayName: '软解'};
  ring_buffer_default_size: SimpleJsonFormatter = {propName: 'ring_buffer_default_size', displayName: '缓冲区默认ts数据包数'};
  decsa_default_delay: SimpleJsonFormatter = {propName: 'decsa_default_delay', displayName: '默认解扰延迟时间'};
  send_default_delay: SimpleJsonFormatter = {propName: 'send_default_delay', displayName: '默认发送解扰延迟时间'};
  unicast: SimpleJsonFormatter = {propName: 'unicast', displayName: '是否开启单播'};
  port_http: SimpleJsonFormatter = {propName: 'port_http', displayName: '信号强度'};
  psi_tables_filtering: SimpleJsonFormatter = {propName: 'psi_tables_filtering', displayName: '丢包策略'};
  autoconf_sid_list: SimpleJsonFormatter = {propName: 'autoconf_sid_list', displayName: '服务列表'};
  status: SimpleJsonFormatter = {propName: 'status_display', displayName: '状态', dynamicComponent: {component: BadgeComponent}};

  constructor(public unitPipe: UnitPipe,
              public badgePipe: BadgePipe) {
    /**
     * 由于这里使用的是内置pipe，所以这里datePipe的参数必须使用null来填充可选参数，
     * 否则format无法将originData传入PipeTransform, 需要OriginData来做更多的事情
     * */
    this.freq.pipe = {pipeTransform: this.unitPipe, args: ['KHZ', 1]};
    this.srate.pipe = {pipeTransform: this.unitPipe, args: ['KHZ', 1]};
    this.status.pipe = new SimplePipe(this.badgePipe, [['未配置', '未启动', '运行中'], ['badge-orange', 'badge-warning', 'badge-success']]);
  }

  get formatter() {
    return [
      this.name,
      this.freq,
      this.status,
    ];
  }

  get timeFormatter() {
    return [
      this.name,
      this.freq,
      this.status,
      this.time
    ];
  }
}
